<template>
  <div class="app">
    <nav class="navbar">
      <div class="nav-content">
        <div class="nav-logo">
          <router-link to="/">对话分析助手</router-link>
        </div>
        <div class="nav-links">
          <router-link to="/" class="nav-link" :class="{ active: currentRoute === '/' }">首页</router-link>
          <router-link to="/analysis" class="nav-link" :class="{ active: currentRoute === '/analysis' }">分析</router-link>
        </div>
      </div>
    </nav>

    <main>
      <router-view v-slot="{ Component }" :key="routeKey">
        <transition name="fade" mode="out-in">
          <component :is="Component" />
        </transition>
      </router-view>
    </main>

    <footer class="footer">
      <div class="footer-content">
        <p>&copy; 2025 对话分析助手. build by trae.</p>
      </div>
    </footer>
  </div>
</template>

<script setup lang="ts">
import { useRoute } from 'vue-router'
import { computed, ref, watch } from 'vue'

const route = useRoute()
const currentRoute = computed(() => route.path)

// 用于强制刷新组件的key
const routeKey = ref(0)

// 监听路由变化，强制刷新组件
watch(() => route.path, () => {
  console.log('Route changed, forcing refresh')
  routeKey.value++
})
</script>

<style>
:root {
  --color-primary: #4169E1;
  --color-primary-rgb: 65, 105, 225;
  --color-primary-light: #6A8EE5;
  --color-secondary: rgba(65, 105, 225, 0.1);
  --color-text: #1a1a1a;
  --color-text-light: #666666;
  --card-shadow: 
    0 4px 6px rgba(0, 0, 0, 0.02),
    0 10px 15px rgba(0, 0, 0, 0.03);
  --card-shadow-hover: 
    0 8px 12px rgba(0, 0, 0, 0.04),
    0 16px 24px rgba(0, 0, 0, 0.06);
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif;
  line-height: 1.6;
  color: var(--color-text);
  background: #f8fafc;
}

.app {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.navbar {
  background: #ffffff;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
  position: fixed;
  width: 100%;
  top: 0;
  z-index: 1000;
}

.nav-content {
  max-width: 1200px;
  margin: 0 auto;
  padding: 1rem 2rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.nav-logo {
  cursor: pointer;
  user-select: none;
}

.nav-logo a {
  font-size: 1.5rem;
  font-weight: 600;
  color: var(--color-primary);
  margin: 0;
  text-decoration: none;
}

.nav-links {
  display: flex;
  gap: 2rem;
}

.nav-link {
  background: none;
  border: none;
  font-size: 1rem;
  font-weight: 500;
  color: var(--color-text);
  cursor: pointer;
  transition: color 0.2s ease;
  padding: 0.5rem 1rem;
  border-radius: 0.5rem;
  text-decoration: none;
}

.nav-link:hover,
.nav-link.active {
  color: var(--color-primary);
  background: var(--color-secondary);
}

main {
  flex: 1;
  margin-top: 64px;
  padding: 0;
}

.footer {
  background: #ffffff;
  padding: 1.5rem 0;
  margin-top: auto;
}

.footer-content {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 2rem;
  text-align: center;
  color: var(--color-text-light);
}

/* Transitions */
.fade-enter-active,
.fade-leave-active {
  transition: opacity 0.3s ease;
}

.fade-enter-from,
.fade-leave-to {
  opacity: 0;
}
</style>
